package com.job.sun.HomeWork0722;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author 张春阳
 * @version 1.0
 * @since 2022-07-22 22:46:39
 */
public class Pick {
    public static Map<String , Integer> pick(String string) throws NullLettersAndNumbersException, OnlHaveNullException {
      Map<String ,Integer> map =new LinkedHashMap<>();
        int count =0;
        if (string==null){
            throw new OnlHaveNullException("字符串为null");
        }
        char[] chars = string.toCharArray();
        for (char aChar : chars) {
            if(Character.isLetterOrDigit(aChar)){
                count++;
                String string1 = Character.toString(aChar);
                if (!map.containsKey(string1)){

                    map.put(string1, 1);
                } else{
                    Integer integer = map.get(string1);
                    integer++;
                    map.put(string1, integer);
                }
            }
        }
        if(count==0){
            throw new NullLettersAndNumbersException("字符串内没有字母和数字");
        }
        return map;
    }


}